<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/jquery.md5.js"></script>
<div class="profiltop"><?php echo $this->translate( 'profil_header' ) ?></div>
<?php if( !$this->userData ) { ?>

<?php echo $this->inlineScript()->setScript('
	$(document).ready(function(){
		$.validator.setDefaults({
			submitHandler: function(e) { 
				var fields = $(e).find( "input.style1" );
				
				$("#login-form5").animate({
					opacity: 0
				});
				
				$.post(
					baseUrl + "/index/login",
					{
						login : $( "#log_mail" ).val(),
						password : $.md5( $("#log_pass" ).val() ),
						json : true
					},
					function( resp ){
						if( resp.status ) {
							window.location.reload();
						} else {
							alert( "' . $this->translate( 'error_login' ) . '" );
							$("#login-form5").animate({
								opacity: 1
							});
						}
					},
					"json"
				);
			}
		});
	
		$("#form1log").validate({
			rules: {
				email : {
					required: true,
					email: true
				},
				pass : {
					required: true,
					minlength: 2
				}
			},
			messages: {
				email : "' . $this->translate( 'error_email' ) . '",
				pass : "'. $this->translate( 'error_password' ) .'"
			}
		});
	});
	') ?>
	
<div class="box nomtop " id="login-form5">

<h1><?php echo $this->translate( 'shop_bon_logowanie' ); ?></h1>

<form id="form1log" method="post" action="">
<table class="tab">
	<tr>
		<td class="aright"><?php echo $this->translate( 'shop_bon_login' ); ?>:</td>
		<td><input type="text" name="email" id="log_mail" value="" class="type5"></td>
	</tr>
	<tr>
		<td class="aright"><?php echo $this->translate( 'shop_bon_pass' ); ?>:</td>
		<td><input type="password" name="password" id="log_pass" value="" class="type5"></td>
	</tr>
</table>
</form>

<div class="line" style="margin:10px 0"></div>

<div class="acenter">
<a href="javascript:;" class="button" onclick="$('#form1log').submit()"><?php echo $this->translate( 'shop_bon_logowanie' ); ?></a>
</div>

<div class="acenter" style="margin-top:20px">
<p>

	<a href="{baseUrl}/index/newaccount" class="orange"><?php echo $this->translate( 'basket_newaccount' ) ?></a> <span style="margin:0 10px">/</span> <a href="{baseUrl}/index/remindpass"><?php echo $this->translate( 'basket_remind' ) ?></a></p>
</div>

<div class="end"></div>

	
</div>
<?php } else { ?>
<div class="box boxprofile">
	
	<div class="menu">
		<div class="acenter">
			<a href="{baseUrl}/shop/account" class="button prodmenu buttonactive"><?php echo $this->translate( 'my_details' ) ?></a>
			<a href="{baseUrl}/shop/orders" class="button prodmenu"><?php echo $this->translate( 'my_orders' ) ?></a>
			<a href="{baseUrl}/shop/observed" class="button prodmenu"><?php echo $this->translate( 'my_observed' ) ?></a>
			<a href="{baseUrl}/shop/vouchers" class="button prodmenu"><?php echo $this->translate( 'my_vouchers' ) ?></a>
		</div>
	</div>
	

	<?php echo $this->inlineScript()->setScript('
	$(document).ready(function(){
	$.validator.addMethod("nameRegex", 
		function(value, element) {
        	return this.optional(element) || /^[^0-9]+$/i.test(value);
    }, 
    "Możesz używać tylko liter.");

	$.validator.addMethod("zipRegex", 
		function(value, element) {
        	return this.optional(element) || /^\d{2}-\d{3}$/i.test(value);
    }, 
    "Zly kod pocztowy.");
    
	$.validator.addMethod("telRegex", 
		function(value, element) {
        	return this.optional(element) || /^[0-9\-\ \(\)\+]+$/i.test(value);
    }, 
    "' . $this->translate( 'error_phone' ) . '");
    
    $.validator.addMethod("bdRegex", 
		function(value, element) {
        	return (value < 32) ? true : false;
    }, 
    "' . $this->translate( 'club_error_birthday_day' ) . '");
   
    $.validator.addMethod("bmRegex", 
		function(value, element) {
        	return (value < 13) ? true : false;
    }, 
    "' . $this->translate( 'club_error_birthday_month' ) . '");
    
    $.validator.addMethod("byRegex", 
		function(value, element) {
        	return (value > 1900 && value <= (new Date).getFullYear()) ? true : false;
    }, 
    "' . $this->translate( 'club_error_birthday_year' ) . '");
    
		$("#reg-form").validate({
			rules: {
				name : {
					required: true,
					minlength: 2,
					maxlength:250,
					nameRegex: true
															
				},
				surname : {
					required: true,
					minlength: 2,
					maxlength:250,
					nameRegex: true
				},
				email : {
					required: true,
					maxlength:255,
					email: true
				},
				phone : {
					minlength: 7,
					maxlength: 30,
					telRegex: true
				},
				zip : {
					zipRegex: true,
					maxlength:10
				},
				locality : {
					required: true,
					maxlength:250,
					minlength: 5
				},
				street : {
					required: true,
					maxlength:255,
					minlength: 3
				},
				nr_home : {
					required: true,
					maxlength:10
				},
				nr_flat : {
					maxlength:10
				},
				rules : {
					required: true
				},
				rules2 : {
					required: true
				},
				birthday_day : {
					required: true,
					minlength: 1,
					number:true,
					maxlength: 2,
					bdRegex: true
				},
				birthday_month : {
					required: true,
					minlength: 2,
					number:true,
					maxlength: 2,
					bmRegex: true
				},
				birthday_year : {
					required: true,
					minlength: 4,
					number:true,
					maxlength: 4,
					byRegex: true
				}
			},
			messages: {
				name : "' . $this->translate( 'error_name' ) . '",
				surname : "' . $this->translate( 'error_surname' ) . '",
				email : "' . $this->translate( 'error_email' ) . '",
				phone : "' . $this->translate( 'error_phone' ) . '",
				street : "' . $this->translate( 'error_street' ) . '",
				locality : "' . $this->translate( 'error_locality' ) . '",
				nr_home : "' . $this->translate( 'error_nr_home' ) . '",
				rules : "' . $this->translate( 'error_rules' ) . '",
				rules2 : "' . $this->translate( 'error_rules2' ) . '",
				birthday_day : "' . $this->translate( 'club_error_birthday_day' ) . '",
				birthday_month : "' . $this->translate( 'club_error_birthday_month' ) . '",
				birthday_year : "' . $this->translate( 'club_error_birthday_year' ) . '"
			}
		});
		
		$("#countrystylish").change(function(){

			if( $(this).val() != "PL" ) {
				$("#province_cn").animate({ opacity: 0 });
			} else {
				$("#province_cn").animate({ opacity: 1 });
			}
		
		});
		
	});
	'); ?>

	<form id="reg-form" method="post" action="">
	<table class="tab">
		<tr>
			<td class="aright"><?php echo $this->translate( 'company_name' ); ?>:</td>
			<td><input type="text" name="company_name" value="<?php echo $this->company_name ?>"></td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'nip' ); ?>P:</td>
			<td><input type="text" id="cnip" name="nip" value="<?php echo $this->nip ?>"></td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'name' ); ?>:</td>
			<td><input type="text" id="cname" name="name" value="<?php echo $this->name ?>"></td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'surname' ); ?>:</td>
			<td><input type="text" id="csurname" name="surname" value="<?php echo $this->surname ?>"></td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'phone' ); ?>:</td>
			<td><input type="text" id="cphone" name="phone" value="<?php echo $this->phone ?>"></td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'birthday' ); ?>:</td>
			<td>
			<input type="text" name="birthday_day" value="<?php echo $this->birthday_day ?>" maxlength="2" style="width:30px"> /
			<input type="text" name="birthday_month" value="<?php echo $this->birthday_month ?>" maxlength="2" style="width:30px"> /
			<input type="text" name="birthday_year" value="<?php echo $this->birthday_year ?>" maxlength="4" style="width:30px">
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'locality' ); ?></td>
			<td><input type="text" id="clocality" name="locality" value="<?php echo $this->locality ?>"></td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'street' ); ?>:</td>
			<td><input type="text" id="cstreet" name="street" value="<?php echo $this->street ?>"></td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'nr_home_reg' ); ?>:</td>
			<td><input type="text" name="nr_home" value="<?php echo ( $this->nr_home < 1 ) ? '' : $this->nr_home; ?>"></td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'nr_flat_reg' ); ?>:</td>
			<td><input type="text" name="nr_flat" value="<?php echo ( $this->nr_flat < 1 ) ? '' : $this->nr_flat;  ?>"></td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'zip' ); ?>:</td>
			<td><input type="text" id="czip" name="zip" value="<?php echo $this->zip ?>"></td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'province' ); ?>:</td>
			<td>
			<?php echo $this->formSelect( 'province', $this->province, array(
					 'id'=>'provincesylish'
				), Core_Static::$province ) ?>
			</td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'country' ); ?>:</td>
			<td>
			<?php echo $this->formSelect( 'country', ( $this->country ) ? $this->country : 'PL', array(
					'id'=>'countrystylish'
				), Core_Static::$country ) ?>
				<?php echo $this->inlineScript()->setScript( '
				$( "#country" ).change(function(){
					console.log( $(this).val() );
					
					if( $(this).val() != "PL" ) {
						$( "#provincesylish" ).animate({ opacity: 0 });
					} else {
						$( "#provincesylish" ).animate({ opacity: 1 });
					}
	
				});
			' ); ?>
			</td>
		</tr>
		<tr>
			<td class="acenter" colspan="2"><p class="mtop15"><a href="javascript:;" onclick="$('#reg-form').submit()" class="button sh"><?php echo $this->translate( 'save' ); ?></a></p></td>
		</tr>
	</table>
	</form>
	<?php echo $this->inlineScript()->setScript('
	$(document).ready(function(){
		$("#chpass-form").validate({
			rules: {
				actpass : {
					required: true,
					minlength: 5
				},
				pass : {
					required: true,
					minlength: 5
				},
				password_retype : {
					required: true,
					minlength: 5,
					equalTo: "#cpass"
				}
			},
			messages: {
				actpass : "' . $this->translate( 'error_actpass' ) . '",
				pass : "'. $this->translate( 'error_password' ) .'",
				password_retype : "'. $this->translate( 'error_retype_password' ) .'"
			}
		});
	});
	'); ?>
	<h2><?php echo $this->translate( 'chpass' ) ?></h2>
	<?php if( $this->error_pass ) { ?>
	<p>
		<?php echo $this->translate( 'error_chpass' ) ?>
	</p>
	<?php }?>
	<?php if( $this->ok_pass ) { ?>
	<p>
		<?php echo $this->translate( 'ok_chpass' ) ?>
	</p>
	<?php } ?>
		<form id="chpass-form" method="post" action="{baseUrl}/shop/chpass">
		<table class="tab">
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'actual_pass' ); ?>:</td>
			<td><input type="password" id="cactpass" name="actpass" value=""></td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'new_pass' ); ?>:</td>
			<td><input type="password" id="cpass" name="pass" value=""></td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'retype_new_pass' ); ?>:</td>
			<td><input type="password" id="password_retype" name="password_retype" value=""></td>
		</tr>
		<tr>
			<td class="acenter" colspan="2"><p class="mtop15"><a onclick="$('#chpass-form').submit()" class="button sh"><?php echo $this->translate( 'save' ); ?></a></p></td>
		</tr>
		</table>
		</form>
	
	<h2><?php echo $this->translate( 'delete_account' ) ?></h2>
	
	<div class="acenter">
	<p class="orange"><?php echo $this->translate( 'delete_info' ); ?></p>
	<p class="mtop15"><a href="{baseUrl}/shop/delete" class="button"><?php echo $this->translate( 'delete_account' ); ?></a></p>
	</div>
	
	<div class="end"></div>
</div>
	

	 
<?php } ?>